package com.janj.utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
//使用自己的连接池
public class MyDataSourceTest {
    public static void main(String[] args) throws Exception {
        //1.创建连接池对象
        MyDataSource ds = new MyDataSource();

        //2.通过连接池对象获取连接对象
        Connection conn = ds.getConnection();

        //3.查询学生表的全部信息
        String sql = "SELECT * FROM student";
        PreparedStatement pp = conn.prepareStatement(sql);

        //4.执行sql语句, 接收结果集
        ResultSet resu = pp.executeQuery();

        //5.处理结果集
        while (resu.next())
            System.out.println(resu.getInt("id") + "\t" + resu.getString("name") + "\t" + resu.getInt("age"));

        //6.释放资源
        resu.close();
        pp.close();
        conn.close();
        System.out.println("使用之后的数量"+ ds.getSize());
    }
}
